package com.talon.ijk_player;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import com.talon.lib_base.ConfigApi;

import tv.danmaku.ijk.media.player.IMediaPlayer;

public class IjkPlayerActivity extends AppCompatActivity {
    private VideoPlayerIJK mVideoPlayerIJK;
    public static String videoUrl = ConfigApi.videoUrl;
    private long time = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.talon.ijk_player.R.layout.activity_ijk_player);
        mVideoPlayerIJK=findViewById(com.talon.ijk_player.R.id.video_ijk);
        mVideoPlayerIJK.setVideoPath(videoUrl);
        time = System.currentTimeMillis();
        mVideoPlayerIJK.start();

        mVideoPlayerIJK.setListener(new VideoPlayerListener() {
            @Override
            public void onBufferingUpdate(IMediaPlayer iMediaPlayer, int i) {

            }

            @Override
            public void onCompletion(IMediaPlayer iMediaPlayer) {

            }

            @Override
            public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) {
                return false;
            }

            @Override
            public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) {
                return false;
            }

            @Override
            public void onPrepared(IMediaPlayer iMediaPlayer) {
                float result = System.currentTimeMillis() - time;
                Log.i("xiaote", " IjkPlayer ~~~~~playbackState :time  ::" + result);
            }

            @Override
            public void onSeekComplete(IMediaPlayer iMediaPlayer) {

            }

            @Override
            public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) {

            }
        });

    }

    @Override
    protected void onPause() {
        super.onPause();
        mVideoPlayerIJK.stop();
        mVideoPlayerIJK.release();
    }
}